package jianzhi_offer;

public class _11_数值的整数次方 {
	//用递归 分奇数和偶数 快速幂的思想
	public double Power(double base, int exponent) {
		// return Math.pow(base,exponent);
		if (exponent == 0 && base != 0)
			return 1;
		if (exponent == 1)
			return base;
		if (base == 0 && exponent <= 0) {
			throw new RuntimeException();
		}
		if (base == 0 && exponent > 0) {
			return 0;
		}
		int n = exponent;
		if (exponent < 0) {
			n = -exponent;
		}
		double result = Power(base, n >> 1);
		result *= result;
		if ((n & 1) == 1)
			result *= base;
		if (exponent < 0)
			result = 1 / result;
		return result;
	}
}
